//
//  WHRPrivateOrderCell.m
//  AnXin100
//
//  Created by 天质弘耕 on 2018/12/11.
//  Copyright © 2018 tzhg. All rights reserved.
//

#import "WHRPrivateOrderCell.h"
#import "UIView+SDAutoLayout.h"
#import "ZXCategories.h"
#import "AXMyMenuCollectionViewCell.h"


@interface  WHRPrivateOrderCell ()<UICollectionViewDelegateFlowLayout, UICollectionViewDataSource>
//CollectionView数据
@property (nonatomic, strong) NSArray<NSString *> *imageNames;
@property (nonatomic, strong) NSArray<NSString *> *titles;

@property (nonatomic, strong) UICollectionView *collectionView;

@property (nonatomic, strong) NSArray *arrayData;
@end

@implementation WHRPrivateOrderCell

- (instancetype)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier {
    
    if (self = [super initWithStyle:style reuseIdentifier:reuseIdentifier]) {
        [self initDatas];
        [self creatView];
        [self setlayout];
    }
    return self;
}

- (void)initDatas {
    
    self.imageNames = @[@"wdzc",@"yhzx",@"wdfx",@"wdzj",@"bzkf",@"sqrz"];
    self.titles = @[@"我的诊断", @"诊断抢单", @"方案管理",@"我的评价"];
    
    _arrayData = @[@{@"data" : @[@{@"title" : @"我的资产",
                                   @"icon" : @"wdzc"},
                                 @{@"title" : @"会员中心",
                                   @"icon" : @"yhzx"},
                                 @{@"title" : @"我的分享",
                                   @"icon" : @"wdfx"},
                                 @{@"title" : @"我的足迹",
                                   @"icon" : @"wdzj"},
                                 @{@"title" : @"帮助/客服",
                                   @"icon" : @"bzkf"},
                                 @{@"title" : @"申请入驻",
                                   @"icon" : @"sqrz"}]},
                   @{@"data" : @[@{@"title" : @"我的诊断",
                                   @"icon" : @"wdzc"},
                                 @{@"title" : @"我的农资",
                                   @"icon" : @"yhzx"},
                                 @{@"title" : @"诊断抢单",
                                   @"icon" : @"wdfx"},
                                 @{@"title" : @"方案管理",
                                   @"icon" : @"wdzj"},
                                 @{@"title" : @"我的评价",
                                   @"icon" : @"bzkf"}]}];
    
}

- (void)creatView {
    
    /** collectionView */
    
    UICollectionViewFlowLayout *flowLayout = [[UICollectionViewFlowLayout alloc]init];
    flowLayout.itemSize = CGSizeMake((SCREEN_WIDTH)/4.0, 110);
    /** 最小行间距 */
    flowLayout.minimumLineSpacing = 5;
    /** 最小列间距 */
    flowLayout.minimumInteritemSpacing = 0;
    BOOL isEnter = [[NSUserDefaults standardUserDefaults] boolForKey:@"EnterAgriculture"];
    
    self.collectionView = [[UICollectionView alloc]initWithFrame:CGRectMake(0, 0, SCREEN_WIDTH, 255) collectionViewLayout:flowLayout];
    if (isEnter) {
        self.collectionView.mj_h = 510;
    }
    self.collectionView.backgroundColor = [UIColor whiteColor];
    [self.collectionView registerClass:[AXMyMenuCollectionViewCell class] forCellWithReuseIdentifier:[AXMyMenuCollectionViewCell reuseID]];
    [self.collectionView registerClass:[UICollectionReusableView class] forSupplementaryViewOfKind:UICollectionElementKindSectionHeader withReuseIdentifier:@"header"];
    
    self.collectionView.delegate = self;
    self.collectionView.dataSource = self;
    [self.contentView addSubview:self.collectionView];
}

- (void)setlayout {
    
}

- (void)setIsShow:(BOOL)isShow {
    _isShow = isShow;
    [_collectionView reloadData];
}

#pragma mark - Collection View Data Source
/** 定义展示的section的个数 */

- (NSInteger)numberOfSectionsInCollectionView:(UICollectionView *)collectionView {
    if (_isShow) {
        return _arrayData.count;
        
    } else {
        return 1;
    }
}
/** 定义展示的collectionCell的个数 */
- (NSInteger)collectionView:(UICollectionView *)collectionView numberOfItemsInSection:(NSInteger)section {
    
    NSArray *array = _arrayData[section][@"data"];
    return array.count;
    
}

- (UICollectionViewCell *)collectionView:(UICollectionView *)collectionView cellForItemAtIndexPath:(NSIndexPath *)indexPath {
    
    NSArray *array = _arrayData[indexPath.section][@"data"];
    AXMyMenuCollectionViewCell *cell = [collectionView dequeueReusableCellWithReuseIdentifier:[AXMyMenuCollectionViewCell reuseID] forIndexPath:indexPath];
    [cell.btn setImage:[UIImage imageNamed:array[indexPath.row][@"icon"]] forState:UIControlStateNormal];
    cell.nameLabel.text = array[indexPath.row][@"title"];
    return cell;
}

#pragma mark - collectionViewDelegateFlowLayout

/** UICollectionView被选中时的方法 */

- (void)collectionView:(UICollectionView *)collectionView didSelectItemAtIndexPath:(NSIndexPath *)indexPath {
    
    if (self.tapButtonClickedBlock) {
        self.tapButtonClickedBlock(indexPath.row,indexPath.section);
    }
    
}

- (UICollectionReusableView *)collectionView:(UICollectionView *)collectionView viewForSupplementaryElementOfKind:(NSString *)kind atIndexPath:(NSIndexPath *)indexPath
{
    
    if (indexPath.section == 1) {
        //如果是头视图
        if ([kind isEqualToString:UICollectionElementKindSectionHeader]) {
            UICollectionReusableView *header=[collectionView dequeueReusableSupplementaryViewOfKind:kind withReuseIdentifier:@"header" forIndexPath:indexPath];
            UILabel *label = [[UILabel alloc] initWithFrame:CGRectMake(10, 0, SCREEN_WIDTH - 20, 30)];
            label.text = @"私人订制";
            label.font = FONT_FOURTEEN;
            label.textColor = COLOR_DIV;
            [header addSubview:label];
            return header;
        }
        //如果底部视图
        //    if([kind isEqualToString:UICollectionElementKindSectionFooter]){
        //
        //    }
        return nil;
    } else {
        return nil;
    }
    
}

- (CGSize)collectionView:(UICollectionView *)collectionView layout:(UICollectionViewLayout *)collectionViewLayout referenceSizeForHeaderInSection:(NSInteger)section {
    if (section == 1) {
        return CGSizeMake(SCREEN_WIDTH, 30);
    } else {
        return CGSizeZero;
    }
}



#pragma mark - Setter & Getter

//- (NSMutableArray<ZXResourceModel *> *)modelsArray {
//    if (!_modelsArray) {
//        _modelsArray = [NSMutableArray<ZXResourceModel *> array];
//    }
//    return _modelsArray;
//}


@end
